/***
 * author: Adam Pociejowski
 */

package requests;

import org.apache.tools.ant.DirectoryScanner;
import main.DemiGui;

public class FileFinder implements IRequest {
	
	private DemiGui instance = null;
	
	public FileFinder(DemiGui instance) {
		
		this.instance = instance;
		
	}

	public String[] Find(String path, String catchWord) {
		
	/******* Looking for file with catchWord in name and returning first one *******/
		
		DirectoryScanner scanner = new DirectoryScanner();
		scanner.setIncludes(new String[] {  "*" + catchWord + "*.mp3"  });
		scanner.setBasedir(path);
		scanner.setCaseSensitive(false);
		scanner.scan();
		String[] files = scanner.getIncludedFiles();
		
		if (files.length > 0) {
			return(files);
		}
		else {
			returnDEMI("File not found!");
			System.out.println("File not found!");
			String tmp[] = new String[1];
			tmp[0] = "";
			return tmp;
		}
		
	/*********************************************************************************/
		
	}

	@Override
	public void returnDEMI(String text) {
		instance.Monitor(text);
	}

}
